package com.taijia.chapter9;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 2015/2/3
 * Time: 21:09
 * To change this template use File | Settings | File Templates.
 */
public class TestJoin {
    public static void main(String[] args) {
        Thread mt2= new MyThread2("t1");
        mt2.start();
        try {
            mt2.join();
        } catch (InterruptedException e) {

        }
        for (int i = 0; i < 10; i++) {
            System.out.println("I am main Thread");
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class MyThread2 extends Thread {
    MyThread2(String s) {
        super(s);
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("I am " + getName());
            try {
                sleep(300);
            } catch (InterruptedException e) {
                return;
            }
        }
    }
}